#!/bin/bash
if [[ $(whoami) != "root" ]]; then
	echo "Please login as user root...";
	exit 1;
elif [ -d /sources ] && [[ $LFS == "" ]]; then
	echo "LFS system entered, strip now";
	find /{,usr/}{bin,lib,sbin} -type f \
		-exec strip --strip-unneeded '{}' ';'
	rm -rvf /tmp/*;
	exit;

elif [ -d $LFS ]; then
	chroot $LFS /tools/bin/env -i            \
		HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
		PATH=/bin:/usr/bin:/sbin:/usr/sbin   \
		/sources/prepare/strip.sh
	if (($? != 0)); then
		echo "Aborted...";
	elif [ -d $LFS/tools ]; then
		tar -czvvf $LFS/tools-lfs-7.6.tar.gz -C $LFS tools || { echo "Failed compressing tools"; exit 2; }
		rm -Rfv $LFS/tools
	else
		if [ -e tools-lfs-7.6.tar.gz ]; then
			echo "$LFS/tools are already archived...";
		else
			echo "$LFS/tools-lfs-7.6.tar.gz not found";
			errcho "$LFS/tools missing!";
		fi
	fi
fi
